<template>
  <div class="ui-starts">
    <span
      v-for="number in 5"
      :key="number"
      :class="['iconfont', number <= startsNum ? 'active' : '']"
      :style="{ fontSize: size + 'px' }"
      @click="setStartsNum(number)"
    >
      &#xe606;
    </span>
  </div>
</template>

<script>
export default {
  name: 'Starts',
  props: {
    num: {
      type: Number,
      default: 0
    },
    size: {
      type: Number,
      default: 16
    }
  },
  data () {
    return {
      startsNum: this.num
    }
  },
  methods: {
    // 点击时几颗星星亮
    setStartsNum (number) {
      this.startsNum = number
      // 将星星点亮了的颗数数据发送到外部
      this.$emit('getStartsNum', this.startsNum)
    }
  }
}
</script>

<style lang="scss" scoped>
@font-face {
  font-family: 'iconfont'; /* project id 2449838 */
  src: url('//at.alicdn.com/t/font_2449838_loiabaphgu.eot');
  src: url('//at.alicdn.com/t/font_2449838_loiabaphgu.eot?#iefix')
      format('embedded-opentype'),
    url('//at.alicdn.com/t/font_2449838_loiabaphgu.woff2') format('woff2'),
    url('//at.alicdn.com/t/font_2449838_loiabaphgu.woff') format('woff'),
    url('//at.alicdn.com/t/font_2449838_loiabaphgu.ttf') format('truetype'),
    url('//at.alicdn.com/t/font_2449838_loiabaphgu.svg#iconfont') format('svg');
}

.iconfont {
  font-family: 'iconfont' !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #ccc;

  &.active {
    color: #fcc33f;
  }
}
</style>
